import { defHttp } from '/@/utils/http/axios';
import { DeptReq, DeptResp } from '/@/api/system/modal/deptModel';
import { MICRO_SERVICE_ADMIN } from '/@/api/ServiceConstant';
import { MenuReq, MenuResp } from '/@/api/system/modal/menuModel';
import { RoleReq, RoleResp } from '/@/api/system/modal/roleModel';
import { Page, Query } from '/@/api/model/baseModel';
import { UserReq, UserResp } from '/@/api/system/modal/userModel';
import { PermissionMenuReq } from '/@/api/system/modal/permissionMenuModel';
import { ApiReq, ApiResp } from '/@/api/system/modal/apiModel';
import { PermissionComponentReq } from '/@/api/system/modal/permissionComponentModel';
import { PermissionReq, PermissionResp } from '/@/api/system/modal/permissionModel';
import { PermissionApiReq } from '/@/api/system/modal/permissionApiModel';
import { ComponentReq, ComponentResp } from '/@/api/system/modal/componentModel';

enum Api {
  QUERY_DEPT_TREE_LIST = '/webservice/dept/queryDeptTreeList',
  CREATE_DEPT = '/webservice/dept/createDept',
  MODIFY_DEPT = '/webservice/dept/modifyDept',
  REMOVE_DEPT_BY_ID = '/webservice/dept/removeDeptById',

  QUERY_MENU_TREE_LIST = '/webservice/menu/queryMenuTreeList',
  QUERY_MENU_CHECKED_TREE_LIST_OF_PERMISSION_ID = '/webservice/menu/queryMenuCheckedTreeListOfPermissionId',
  QUERY_CHECKED_MENU_TREE_LIST_BY_PERMISSION_ID = '/webservice/menu/queryCheckedMenuTreeListByPermissionId',
  CREATE_MENU = '/webservice/menu/createMenu',
  MODIFY_MENU = '/webservice/menu/modifyMenu',
  REMOVE_MENU_BY_ID = '/webservice/menu/removeMenuById',

  QUERY_CONTROL_LIST_BY_MENU_ID = '/webservice/component/queryComponentListByMenuId',
  QUERY_CONTROL_CHECKED_LIST_BY_MENU_ID_OF_PERMISSION_ID = '/webservice/component/queryComponentCheckedListByMenuIdOfPermissionId',
  CREATE_CONTROL = '/webservice/component/createComponent',
  MODIFY_CONTROL = '/webservice/component/modifyComponent',
  REMOVE_CONTROL_BY_ID = '/webservice/component/removeComponentById',

  QUERY_API_LIST_BY_MENU_ID = '/webservice/api/queryApiListByMenuId',
  QUERY_API_CHECKED_LIST_BY_MENU_ID_OF_PERMISSION_ID = '/webservice/api/queryApiCheckedListByMenuIdOfPermissionId',
  CREATE_API = '/webservice/api/createApi',
  MODIFY_API = '/webservice/api/modifyApi',
  REMOVE_API_BY_ID = '/webservice/api/removeApiById',

  QUERY_ROLE_PAGE = '/webservice/role/queryRolePage',
  CREATE_ROLE = '/webservice/role/createRole',
  MODIFY_ROLE = '/webservice/role/modifyRole',
  ENABLED_ROLE_STATE_BY_ID = '/webservice/role/enabledRoleStateById',
  REMOVE_ROLE_BY_ID = '/webservice/role/removeRoleById',
  BIND_ROLE_PERMISSION_RELATION = '/webservice/role/bindRolePermissionRelation',

  QUERY_PERMISSION_PAGE = '/webservice/permission/queryPermissionPage',
  QUERY_PERMISSION_CHECKED_LIST_OF_ROLE_ID = '/webservice/permission/queryPermissionCheckedListOfRoleId',
  CREATE_PERMISSION = '/webservice/permission/createPermission',
  MODIFY_PERMISSION = '/webservice/permission/modifyPermission',
  ENABLED_PERMISSION_STATE_BY_ID = '/webservice/permission/enabledPermissionStateById',
  REMOVE_PERMISSION_BY_ID = '/webservice/permission/removePermissionById',
  BIND_PERMISSION_MENU_RELATION = '/webservice/permission/bindPermissionMenuRelation',
  BIND_PERMISSION_CONTROL_RELATION = '/webservice/permission/bindPermissionComponentRelation',
  BIND_PERMISSION_API_RELATION = '/webservice/permission/bindPermissionApiRelation',

  QUERY_USER_PAGE = '/webservice/user/queryUserPage',
  VERIFY_USERNAME = '/webservice/user/verifyUsername',
  CREATE_USER = '/webservice/user/createUser',
  MODIFY_USER = '/webservice/user/modifyUser',
  REMOVE_USER_BY_ID = '/webservice/user/removeUserById',
  MODIFY_USER_PWD = '/webservice/user/modifyUserPwd',
}

//region 部门接口
export const queryDeptTreeList = (params?: DeptReq) =>
  defHttp.post<DeptResp[]>({
    url: MICRO_SERVICE_ADMIN + Api.QUERY_DEPT_TREE_LIST,
    data: params,
  });

export const createDept = (params: DeptReq) =>
  defHttp.post<DeptResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_DEPT, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyDept = (params: DeptReq) =>
  defHttp.post<DeptResp>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_DEPT, data: params },
    { errorMessageMode: 'message' },
  );

export const removeDeptById = (params: DeptReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_DEPT_BY_ID, params },
    { errorMessageMode: 'message' },
  );
//endregion

//region 菜单接口
export const queryMenuTreeList = (params?: MenuReq) =>
  defHttp.post<MenuResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_MENU_TREE_LIST,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const queryMenuCheckedTreeListOfPermissionId = (params?: PermissionMenuReq) =>
  defHttp.post<MenuResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_MENU_CHECKED_TREE_LIST_OF_PERMISSION_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const queryCheckedMenuTreeListByPermissionId = (params?: PermissionMenuReq) =>
  defHttp.post<MenuResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_CHECKED_MENU_TREE_LIST_BY_PERMISSION_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const createMenu = (params: MenuReq) =>
  defHttp.post<MenuResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_MENU, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyMenu = (params: MenuReq) =>
  defHttp.post<MenuResp>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_MENU, data: params },
    { errorMessageMode: 'message' },
  );

export const removeMenuById = (params: MenuReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_MENU_BY_ID, params },
    { errorMessageMode: 'message' },
  );
//endregion

//region 菜单控件
export const queryComponentListByMenuId = (params?: ComponentReq) =>
  defHttp.post<ComponentResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_CONTROL_LIST_BY_MENU_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const queryComponentCheckedListByMenuIdOfPermissionId = (params?: PermissionComponentReq) =>
  defHttp.post<ComponentResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_CONTROL_CHECKED_LIST_BY_MENU_ID_OF_PERMISSION_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const createComponent = (params: ComponentReq) =>
  defHttp.post<ComponentResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_CONTROL, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyComponent = (params: ComponentReq) =>
  defHttp.post<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_CONTROL, data: params },
    { errorMessageMode: 'message' },
  );

export const removeComponentById = (params: ComponentReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_CONTROL_BY_ID, params },
    { errorMessageMode: 'message' },
  );
//endregion

//region 菜单接口
export const queryApiListByMenuId = (params?: ApiReq) =>
  defHttp.post<ApiResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_API_LIST_BY_MENU_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const queryApiCheckedListByMenuIdOfPermissionId = (params?: PermissionApiReq) =>
  defHttp.post<ApiResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_API_CHECKED_LIST_BY_MENU_ID_OF_PERMISSION_ID,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const createApi = (params: ApiReq) =>
  defHttp.post<ApiResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_API, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyApi = (params: ApiReq) =>
  defHttp.post<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_API, data: params },
    { errorMessageMode: 'message' },
  );

export const removeApiById = (params: ComponentReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_API_BY_ID, params },
    { errorMessageMode: 'message' },
  );
//endregion

//region 角色接口
export const queryRolePage = (params?: Query<RoleReq>) =>
  defHttp.post<Page<RoleResp>>({
    url: MICRO_SERVICE_ADMIN + Api.QUERY_ROLE_PAGE,
    data: params,
  });

export const createRole = (params: RoleReq) =>
  defHttp.post<RoleResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_ROLE, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyRole = (params: RoleReq) =>
  defHttp.post<RoleResp>(
    {
      url: MICRO_SERVICE_ADMIN + Api.MODIFY_ROLE,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const enabledRoleStateById = (params: RoleReq) =>
  defHttp.get<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.ENABLED_ROLE_STATE_BY_ID,
      params: params,
    },
    { errorMessageMode: 'message' },
  );

export const removeRoleById = (params: RoleReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_ROLE_BY_ID, params },
    { errorMessageMode: 'message' },
  );

export const bindRolePermissionRelation = (params: PermissionComponentReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.BIND_ROLE_PERMISSION_RELATION,
      params,
    },
    { errorMessageMode: 'message' },
  );

//endregion

//region 权限接口
export const queryPermissionPage = (params?: Query<PermissionReq>) =>
  defHttp.post<Page<PermissionResp>>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_PERMISSION_PAGE,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const queryPermissionCheckedListOfRoleId = (params?: PermissionReq) =>
  defHttp.get<PermissionResp[]>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_PERMISSION_CHECKED_LIST_OF_ROLE_ID,
      params: params,
    },
    { errorMessageMode: 'message' },
  );

export const createPermission = (params: PermissionReq) =>
  defHttp.post<Boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_PERMISSION, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyPermission = (params: PermissionReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.MODIFY_PERMISSION,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const enabledPermissionStateById = (params: PermissionReq) =>
  defHttp.get<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.ENABLED_PERMISSION_STATE_BY_ID,
      params: params,
    },
    { errorMessageMode: 'message' },
  );

export const removePermissionById = (params: PermissionReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_PERMISSION_BY_ID, params },
    { errorMessageMode: 'message' },
  );

export const bindPermissionMenuRelation = (params: PermissionMenuReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.BIND_PERMISSION_MENU_RELATION,
      params,
    },
    { errorMessageMode: 'message' },
  );

export const bindPermissionComponentRelation = (params: PermissionComponentReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.BIND_PERMISSION_CONTROL_RELATION,
      params,
    },
    { errorMessageMode: 'message' },
  );

export const bindPermissionApiRelation = (params: PermissionApiReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.BIND_PERMISSION_API_RELATION,
      params,
    },
    { errorMessageMode: 'message' },
  );

//endregion

//region 用户接口
export const queryUserPage = (params: UserReq) =>
  defHttp.post<Page<UserResp>>(
    {
      url: MICRO_SERVICE_ADMIN + Api.QUERY_USER_PAGE,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const verifyUsername = (params: UserReq) =>
  defHttp.post<boolean>(
    {
      url: MICRO_SERVICE_ADMIN + Api.VERIFY_USERNAME,
      data: params,
    },
    { errorMessageMode: 'message' },
  );

export const createUser = (params: UserReq) =>
  defHttp.post<UserResp>(
    { url: MICRO_SERVICE_ADMIN + Api.CREATE_USER, data: params },
    { errorMessageMode: 'message' },
  );

export const modifyUser = (params: UserReq) =>
  defHttp.post<UserResp>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_USER, data: params },
    { errorMessageMode: 'message' },
  );

export const removeUserById = (params: UserReq) =>
  defHttp.get<boolean>(
    { url: MICRO_SERVICE_ADMIN + Api.REMOVE_USER_BY_ID, params },
    { errorMessageMode: 'message' },
  );
//endregion

export const modifyUserPwd = (params: UserReq) =>
  defHttp.post<UserResp>(
    { url: MICRO_SERVICE_ADMIN + Api.MODIFY_USER_PWD, data: params },
    { errorMessageMode: 'message' },
  );
